/*
 *  CRoleCreate.cpp
 *  Cocos2dAction
 *
 *  Created by Hunk on 10-6-28.
 *  Copyright 2010 __MyCompanyName__. All rights reserved.
 *
 */

#import "CRoleCreate.h"


CRoleCreate* CRoleCreate::__self = NULL;

CRoleCreate::CRoleCreate()
{
	__NameStore.clear();
	
	__RoleStore.clear();
}

 CRoleCreate* CRoleCreate::Instance()
{
	if(__self == NULL)
	{
		__self = new CRoleCreate();
	}
	return __self;
}

CRoleCreate::	~CRoleCreate()
{
	__NameStore.clear();
	for(int i=0; i<__RoleStore.size();i++)
	{
		delete __RoleStore[i];
		__RoleStore[i] = NULL;
	}
	__RoleStore.clear();
	__self = NULL;
}

Role * CRoleCreate::CreateOneRole(const char* pName)
{
	string roleName = pName;
	bool b_haveRole = false;
	for(int i=0; i< __NameStore.size();i++)
	{
		if(__NameStore[i] == roleName)
		{
			return __RoleStore[i];
		}
	}
	
	Role* pRole = new Role(pName);
	
	if(pRole == NULL)
		return pRole;
	
	int a = __NameStore.size();
	
	__NameStore.insert(pair<int,string>(a,roleName));
	
	__RoleStore.insert(pair<int,Role*>(a,pRole));
	
	return pRole;
	
	
}
